package 笔试;

import java.util.Scanner;

public class 跳石头得分 {
    public static void main(String[] args) {
        int[] a = new int[100005];
        int[] b = new int[100005];
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        for (int i = 0; i < n; i++) {
            a[i] = scan.nextInt();
        }
        for (int i = 0; i < m; i++) {
            b[i] = scan.nextInt();
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if(b[a[i]-1] > 0) {
                ans++;
                b[a[i]-1]--;
            } else {
                break;
            }
        }
        System.out.println(ans * 30);
    }
}
